package com.yct.springcloud.controller;


import com.yct.springcloud.entity.pay.Payment;
import com.yct.springcloud.service.IPaymentService;
import com.yct.springcloud.support.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 支付 前端控制器
 * </p>
 *
 * @author yct
 * @since 2020-07-15
 */
@RestController
@Slf4j
@RequestMapping("/yct/payment")
public class PaymentController {

    @Autowired
    IPaymentService iPaymentService;
    @Value("${server.port}")
    String port;

    /**
     * 插入支付数据
     *
     * @param payment
     * @return
     */
    @PostMapping(value = "/insertPayment")
    public CommonResult insertPayment(@RequestBody Payment payment) {
        boolean result = iPaymentService.save(payment);
        log.info("*****插入支付【" + payment + "】结果：" + result);

        return new CommonResult(200, "插入数据库成功，serverPort = "+ port, payment);
    }

    /**
     * 根据ID查询支付数据
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id) {
        log.info("*****根据id【" + id + "】查询支付数据。");

        return new CommonResult(200, "查询成功，serverPort = "+ port, iPaymentService.getById(id));
    }

}

